<template>
  <div class="app-container">
    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body>
      <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px">
                    <el-form-item label="用户账号" prop="account">
                      <el-input v-model="formData.account" placeholder="请输入用户账号" />
                    </el-form-item>
                    <el-form-item label="用户密码" prop="pwd">
                      <el-input v-model="formData.pwd" placeholder="请输入用户密码" />
                    </el-form-item>
                    <el-form-item label="金料密码" prop="goldPwd">
                      <el-input v-model="formData.goldPwd" placeholder="请输入金料密码" />
                    </el-form-item>
                    <el-form-item label="真实姓名" prop="realName">
                      <el-input v-model="formData.realName" placeholder="请输入真实姓名" />
                    </el-form-item>
                    <el-form-item label="生日" prop="birthday">
                      <el-input v-model="formData.birthday" placeholder="请输入生日" />
                    </el-form-item>
                    <el-form-item label="身份证号码" prop="cardId">
                      <el-input v-model="formData.cardId" placeholder="请输入身份证号码" />
                    </el-form-item>
                    <el-form-item label="用户备注" prop="mark">
                      <el-input v-model="formData.mark" placeholder="请输入用户备注" />
                    </el-form-item>
                    <el-form-item label="合伙人id" prop="partnerId">
                      <el-input v-model="formData.partnerId" placeholder="请输入合伙人id" />
                    </el-form-item>
                    <el-form-item label="用户分组id" prop="groupId">
                      <el-input v-model="formData.groupId" placeholder="请输入用户分组id" />
                    </el-form-item>
                    <el-form-item label="标签id" prop="tagId">
                      <el-input v-model="formData.tagId" placeholder="请输入标签id" />
                    </el-form-item>
                    <el-form-item label="用户昵称" prop="nickname">
                      <el-input v-model="formData.nickname" placeholder="请输入用户昵称" />
                    </el-form-item>
                    <el-form-item label="用户头像" prop="avatar">
                      <el-input v-model="formData.avatar" placeholder="请输入用户头像" />
                    </el-form-item>
                    <el-form-item label="手机号码" prop="phone">
                      <el-input v-model="formData.phone" placeholder="请输入手机号码" />
                    </el-form-item>
                    <el-form-item label="添加ip" prop="addIp">
                      <el-input v-model="formData.addIp" placeholder="请输入添加ip" />
                    </el-form-item>
                    <el-form-item label="最后一次登录ip" prop="lastIp">
                      <el-input v-model="formData.lastIp" placeholder="请输入最后一次登录ip" />
                    </el-form-item>
                    <el-form-item label="用户余额" prop="nowMoney">
                      <el-input v-model="formData.nowMoney" placeholder="请输入用户余额" />
                    </el-form-item>
                    <el-form-item label="用户剩余积分" prop="integral">
                      <el-input v-model="formData.integral" placeholder="请输入用户剩余积分" />
                    </el-form-item>
                    <el-form-item label="用户剩余经验" prop="experience">
                      <el-input v-model="formData.experience" placeholder="请输入用户剩余经验" />
                    </el-form-item>
                    <el-form-item label="连续签到天数" prop="signNum">
                      <el-input v-model="formData.signNum" placeholder="请输入连续签到天数" />
                    </el-form-item>
                    <el-form-item label="1为正常，0为禁止" prop="status">
                      <el-radio-group v-model="formData.status">
                            <el-radio label="1">请选择字典生成</el-radio>
                      </el-radio-group>
                    </el-form-item>
                    <el-form-item label="等级" prop="level">
                      <el-input v-model="formData.level" placeholder="请输入等级" />
                    </el-form-item>
                    <el-form-item label="推广员id" prop="spreadUid">
                      <el-input v-model="formData.spreadUid" placeholder="请输入推广员id" />
                    </el-form-item>
                    <el-form-item label="用户类型" prop="userType">
                      <el-select v-model="formData.userType" placeholder="请选择用户类型">
                            <el-option label="请选择字典生成" value="" />
                      </el-select>
                    </el-form-item>
                    <el-form-item label="推广员关联时间" prop="spreadTime">
                      <el-date-picker clearable v-model="formData.spreadTime" type="date" value-format="timestamp" placeholder="选择推广员关联时间" />
                    </el-form-item>
                    <el-form-item label="是否为推广员" prop="isPromoter">
                      <el-input v-model="formData.isPromoter" placeholder="请输入是否为推广员" />
                    </el-form-item>
                    <el-form-item label="用户购买次数" prop="payCount">
                      <el-input v-model="formData.payCount" placeholder="请输入用户购买次数" />
                    </el-form-item>
                    <el-form-item label="下级人数" prop="spreadCount">
                      <el-input v-model="formData.spreadCount" placeholder="请输入下级人数" />
                    </el-form-item>
                    <el-form-item label="详细地址" prop="addres">
                      <el-input v-model="formData.addres" placeholder="请输入详细地址" />
                    </el-form-item>
                    <el-form-item label="管理员编号 " prop="adminid">
                      <el-input v-model="formData.adminid" placeholder="请输入管理员编号 " />
                    </el-form-item>
                    <el-form-item label="用户登陆类型，h5,wechat,routine" prop="loginType">
                      <el-select v-model="formData.loginType" placeholder="请选择用户登陆类型，h5,wechat,routine">
                            <el-option label="请选择字典生成" value="" />
                      </el-select>
                    </el-form-item>
                    <el-form-item label="最后一次登录时间" prop="lastLoginTime">
                      <el-date-picker clearable v-model="formData.lastLoginTime" type="date" value-format="timestamp" placeholder="选择最后一次登录时间" />
                    </el-form-item>
                    <el-form-item label="清除时间" prop="cleanTime">
                      <el-date-picker clearable v-model="formData.cleanTime" type="date" value-format="timestamp" placeholder="选择清除时间" />
                    </el-form-item>
                    <el-form-item label="推广等级记录" prop="path">
                      <el-input v-model="formData.path" placeholder="请输入推广等级记录" />
                    </el-form-item>
                    <el-form-item label="是否关注公众号" prop="subscribe">
                      <el-input v-model="formData.subscribe" placeholder="请输入是否关注公众号" />
                    </el-form-item>
                    <el-form-item label="关注公众号时间" prop="subscribeTime">
                      <el-date-picker clearable v-model="formData.subscribeTime" type="date" value-format="timestamp" placeholder="选择关注公众号时间" />
                    </el-form-item>
                    <el-form-item label="性别，0未知，1男，2女，3保密" prop="sex">
                      <el-radio-group v-model="formData.sex">
                            <el-radio label="1">请选择字典生成</el-radio>
                      </el-radio-group>
                    </el-form-item>
                    <el-form-item label="国家，中国CN，其他OTHER" prop="country">
                      <el-input v-model="formData.country" placeholder="请输入国家，中国CN，其他OTHER" />
                    </el-form-item>
                    <el-form-item label="成为分销员时间" prop="promoterTime">
                      <el-date-picker clearable v-model="formData.promoterTime" type="date" value-format="timestamp" placeholder="选择成为分销员时间" />
                    </el-form-item>
                    <el-form-item label="邀请码地址" prop="yqm">
                      <el-input v-model="formData.yqm" placeholder="请输入邀请码地址" />
                    </el-form-item>
                    <el-form-item label="认证状态" prop="rz">
                      <el-input v-model="formData.rz" placeholder="请输入认证状态" />
                    </el-form-item>
                    <el-form-item label="邀请码" prop="inviteCode">
                      <el-input v-model="formData.inviteCode" placeholder="请输入邀请码" />
                    </el-form-item>
      </el-form>
              <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import * as AppUserApi from '@/api/system/appuser';
      export default {
    name: "AppUserForm",
    components: {
                    },
    data() {
      return {
        // 弹出层标题
        dialogTitle: "",
        // 是否显示弹出层
        dialogVisible: false,
        // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
        formLoading: false,
        // 表单参数
        formData: {
                            id: undefined,
                            account: undefined,
                            pwd: undefined,
                            goldPwd: undefined,
                            realName: undefined,
                            birthday: undefined,
                            cardId: undefined,
                            mark: undefined,
                            partnerId: undefined,
                            groupId: undefined,
                            tagId: undefined,
                            nickname: undefined,
                            avatar: undefined,
                            phone: undefined,
                            addIp: undefined,
                            lastIp: undefined,
                            nowMoney: undefined,
                            integral: undefined,
                            experience: undefined,
                            signNum: undefined,
                            status: undefined,
                            level: undefined,
                            spreadUid: undefined,
                            userType: undefined,
                            spreadTime: undefined,
                            isPromoter: undefined,
                            payCount: undefined,
                            spreadCount: undefined,
                            addres: undefined,
                            adminid: undefined,
                            loginType: undefined,
                            lastLoginTime: undefined,
                            cleanTime: undefined,
                            path: undefined,
                            subscribe: undefined,
                            subscribeTime: undefined,
                            sex: undefined,
                            country: undefined,
                            promoterTime: undefined,
                            yqm: undefined,
                            rz: undefined,
                            inviteCode: undefined,
        },
        // 表单校验
        formRules: {
                        account: [{ required: true, message: '用户账号不能为空', trigger: 'blur' }],
                        userType: [{ required: true, message: '用户类型不能为空', trigger: 'change' }],
                        loginType: [{ required: true, message: '用户登陆类型，h5,wechat,routine不能为空', trigger: 'change' }],
                        path: [{ required: true, message: '推广等级记录不能为空', trigger: 'blur' }],
        },
                        };
    },
    methods: {
      /** 打开弹窗 */
     async open(id) {
        this.dialogVisible = true;
        this.reset();
        // 修改时，设置数据
        if (id) {
          this.formLoading = true;
          try {
            const res = await AppUserApi.getAppUser(id);
            this.formData = res.data;
            this.title = "修改用户";
          } finally {
            this.formLoading = false;
          }
        }
        this.title = "新增用户";
              },
      /** 提交按钮 */
      async submitForm() {
        // 校验主表
        await this.$refs["formRef"].validate();
                  this.formLoading = true;
        try {
          const data = this.formData;
                  // 修改的提交
          if (data.id) {
            await AppUserApi.updateAppUser(data);
            this.$modal.msgSuccess("修改成功");
            this.dialogVisible = false;
            this.$emit('success');
            return;
          }
          // 添加的提交
          await AppUserApi.createAppUser(data);
          this.$modal.msgSuccess("新增成功");
          this.dialogVisible = false;
          this.$emit('success');
        } finally {
          this.formLoading = false;
        }
      },
                      /** 表单重置 */
      reset() {
        this.formData = {
                            id: undefined,
                            account: undefined,
                            pwd: undefined,
                            goldPwd: undefined,
                            realName: undefined,
                            birthday: undefined,
                            cardId: undefined,
                            mark: undefined,
                            partnerId: undefined,
                            groupId: undefined,
                            tagId: undefined,
                            nickname: undefined,
                            avatar: undefined,
                            phone: undefined,
                            addIp: undefined,
                            lastIp: undefined,
                            nowMoney: undefined,
                            integral: undefined,
                            experience: undefined,
                            signNum: undefined,
                            status: undefined,
                            level: undefined,
                            spreadUid: undefined,
                            userType: undefined,
                            spreadTime: undefined,
                            isPromoter: undefined,
                            payCount: undefined,
                            spreadCount: undefined,
                            addres: undefined,
                            adminid: undefined,
                            loginType: undefined,
                            lastLoginTime: undefined,
                            cleanTime: undefined,
                            path: undefined,
                            subscribe: undefined,
                            subscribeTime: undefined,
                            sex: undefined,
                            country: undefined,
                            promoterTime: undefined,
                            yqm: undefined,
                            rz: undefined,
                            inviteCode: undefined,
        };
        this.resetForm("formRef");
      }
    }
  };
</script>